package edu.auctionmart

import edu.auctionmart.Auction;
import edu.auctionmart.User
import edu.auctionmart.Item
import edu.auctionmart.ItemCategory
import org.joda.time.DateTime
import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Auction)
class AuctionTests {

    void testValidation() {
       
		User seller = new User(username: "Russell", password: "Testinga4b", email: "russell@maine.edu")
		Item item = new Item(name: "Movie", description: "Some movie", category: ItemCategory.Electronics, quantity: 1)
		
		DateTime startTime = new DateTime(2012, 2, 12, 0, 0, 0)
		DateTime endTime = new DateTime(2012, 2, 15, 0, 0, 0)
		
		Auction auction = new Auction(auctionTitle: "Title", startBid: 0.01, seller: seller, item: item, startTime: startTime, endTime: endTime, status: AuctionStatus.OnGoing)
		auction.validate()
		assert(auction.hasErrors() == false)
		
		auction = new Auction(auctionTitle: "Title", startBid: 0.01, seller: seller, item: item, startTime: endTime, endTime: startTime, status: AuctionStatus.OnGoing)
		auction.validate()
		assert(auction.hasErrors() == true)
	
    }
}
